package utilitarios;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;




public class ConnectionHelper{
    
    private static ConnectionHelper instancia = new ConnectionHelper();
    private static Connection con  = null;
    private static String url = "jdbc:derby://localhost:1527/sample;user=appp;password=app";
    
    private ConnectionHelper(){}
    
    public static ConnectionHelper getIntance(){
        return instancia;
    }
    
    public static Connection getConnection(){
        if(con==null){
            try {
                try {
                    Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
                    con = DriverManager.getConnection(url);
                } catch (SQLException ex) {
                    Logger.getLogger(ConnectionHelper.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ConnectionHelper.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (InstantiationException ex) {
                Logger.getLogger(ConnectionHelper.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(ConnectionHelper.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return con;
    }
    
    public void desconecta(){
        con = null;
    }
}

